package com.erdos.upc.dao.ibatis;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;

import com.erdos.common.dao.IBatisGenericDaoImpl;
import com.erdos.common.exception.DaoException;
import com.erdos.upc.dao.UserDao;
import com.erdos.upc.entity.User;


public class UserDaoImpl extends IBatisGenericDaoImpl<User> implements UserDao {
	/**
	 * 插入用户和用户组的关联记录
	 * @param userSid
	 * @param groupSid
	 */
	public void insertUserGroup(Map<String,Object> params) {
		try {
			this.getSqlMapClientTemplate().insert("User.insertUserGroup",
					params);
		} catch (DataAccessException e) {
			throw new DaoException("jdbc.error.code.User.insertUserGroup", new String[] {
					"User.insertUserGroup", params.toString()},e);
		}
	}

	/**
	 * 删除用户和用户组的关联记录
	 * @param userSid
	 * @param groupSid
	 */
	public void deleteUserGroup(Long userSid, Long groupSid) {
		Map<String, Long> conditions = new HashMap<String, Long>();
		conditions.put("userSid", userSid);
		conditions.put("groupSid", groupSid);
		try {
			this.getSqlMapClientTemplate().delete("User.deleteUserGroup",
					conditions);
		} catch (DataAccessException e) {
			throw new DaoException("jdbc.error.code.User.deleteUserGroup", new String[] {"User.deleteUserGroup", conditions.toString()},e);
		}
	}

	/* (non-Javadoc)
	 * @see com.hp.upc.dao.UserDao#findUserByUserNameUserGP(java.util.Map)
	 */
	public User findUserByUserNameUserGP(Map<String, Object> params) 
	{
		return (User)this.getSqlMapClientTemplate().queryForObject("User.findUserByUserNameUserGP", params);
	}

	/* (non-Javadoc)
	 * @see com.hp.upc.dao.UserDao#insertSecurityRole(java.util.Map)
	 */
	public void insertSecurityRole(Map<String, Object> params) {
		this.getSqlMapClientTemplate().insert("User.insertSecurityRole",
				params);	
	}

	/* (non-Javadoc)
	 * @see com.hp.upc.dao.UserDao#deleteSecRoleByUserSidAndsecSid(java.lang.Long, java.lang.Long)
	 */
	public void deleteSecRoleByUserSidAndsecSid(Long userSid, Long securitySid) {
		Map<String, Long> conditions = new HashMap<String, Long>();
		conditions.put("userSid", userSid);
		conditions.put("securitySid", securitySid);
		try {
			this.getSqlMapClientTemplate().delete("User.deleteSecRoleByUserSidAndsecSid",
					conditions);
		} catch (DataAccessException e) {
			throw new DaoException("jdbc.error.code.User.deleteSecRoleByUserSidAndsecSid", new String[] {"User.deleteUserGroup", conditions.toString()},e);
		}
		
	}


}
